fi = open("earpa001.txt","r")
fo =open("earpa001_count.txt","w")
# read() 调用read()方法可以一次读取文件的全部内容
# readlines()可以按照⾏的⽅式把整个⽂件中的内容进⾏⼀次性读取，
# 并且返回的是⼀个列表，其中每⼀⾏的数据为⼀个元素。
# readline()⼀次读取⼀⾏内容。
lines = fi.readlines()
d ={}
for line in lines:
    dateTime,sensor_num,floor,regional = line.strip("\n").split(",")
    location = floor+"-"+regional
    d[location] = d.get(location,0)+1

ls = list(d.items())
ls.sort(key=lambda x:x[1],reverse=True)
for i in range(len(ls)):
    fo.write('{},{}\n'.format(ls[i][0],ls[i][1]))
fi.close()
fo.close()
